<?php
// Init owncloud
OCP\JSON::checkLoggedIn();
OCP\JSON::callCheck();

$app = PFactory::getApplication();
$jobpositiondir = $app->getUserState('jobpositiondir', null);
$neworderby = JRequest::getString('neworderby', '');
$neworderdir = JRequest::getString('neworderdir', '');
$orderby = JRequest::getString('orderby', '');
$orderdir = strtoupper(JRequest::getString('orderdir', ''));
if($neworderby == $orderby) {
   $orderdir = ($orderdir == 'ASC' ? 'DESC' : 'ASC'); 
}
else {
   $orderdir = strtoupper($neworderdir); 
   $orderdir == 'ASC' ? 'ASC' : 'DESC'; 
}

$jobpositiondir['jobsarea']=JArrayHelper::getValue($jobpositiondir, 'jobsarea', '');
$jobpositiondir['jobsmatch']=strtolower(JArrayHelper::getValue($jobpositiondir, 'jobsmatch', 'all'));
$jobpositiondir['jobssync']=JArrayHelper::getValue($jobpositiondir, 'jobssync', '');
$jobpositiondir['jobsdir']=strtolower(JArrayHelper::getValue($jobpositiondir, 'jobsdir', 'all'));
$jobpositiondir['jobskeyword']=JArrayHelper::getValue($jobpositiondir, 'jobskeyword', '');

$jobpositiondir['orderby'] = $neworderby;
$jobpositiondir['orderdir'] = $orderdir; 
$app->setUserState('jobpositiondir', $jobpositiondir);
OC_JSON::success(array("data" =>array()));
exit;
